<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:th="http://www.thymeleaf.org"
	xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3">
<script th:inline="javascript">
/*<![CDATA[*/
   $(function(){
   	 middlegroup.ns('middlegroup.admin.menu[[${OP.menuId}]]');
   	 $('#admin_menu[[${OP.menuId}]]_datagrid').bootstrapTable({ 
		  url:[[${MENU.channel}]]+'/query',
          height: '100%',
          sortName: 'name',
          sortOrder: 'desc',
          striped: true,
          pagination: true,
          pageSize: 10,
          pageList: [10, 25, 50, 100, 200],
          search: false,
          sidePagination:'server',
          idField: 'id',
          uniqueId: 'id',
          responseHandler: responseHandler,
          queryParams: queryParams,
          minimumCountColumns: 2,
          clickToSelect: true,
          searchAlign: 'left',
          columns: [{
              checkbox: true
          }, {
              field: 'name',
              title: '主体全称',
              align: 'center',
              valign: 'middle'
          },
          {
              field: 'shortName',
              title: '主体简称',
              align: 'center',
              valign: 'middle'
          }, {
                  field: 'code',
                  title: '主体编码',
                  align: 'center',
                  valign: 'middle'
              }, {
                  field: 'phone',
                  title: '主体负责人手机号',
                  align: 'center',
                  valign: 'middle'
              }, {
                  field: 'email',
                  title: '主体负责人邮箱',
                  align: 'center',
                  valign: 'middle'
              },{
              field: 'addTime',
              title: '创建时间',
              align: 'center',
              valign: 'middle',
              sortable: true,
              formatter:function(value,row,index){return new Date(value).pattern("yyyy-MM-dd HH:mm:ss")}
          }, {
              field: 'updateTime',
              title: '修改时间',
              align: 'center',
              valign: 'middle',
              sortable: true,
              formatter:function(value,row,index){return new Date(value).pattern("yyyy-MM-dd HH:mm:ss")}
          }  ]
    });
})
    
// 传递的参数
function queryParams(params) {
	return {
		pageSize : params.limit,
		pageNum : params.offset / params.limit + 1,
		sort : params.sort,
		order : params.order,
		name:$("#name").val(),
		code:$("#code").val()
	}
}
//查询
var search = 0;
middlegroup.admin.menu[[${OP.menuId}]].search = function(){
	 if($("#name").val() !='' || $("#account").val() !=''){
		 $('#admin_menu[[${OP.menuId}]]_datagrid').bootstrapTable('refresh');
		 search++;
	 } else {
		 if(search != 0) {
			 $('#admin_menu[[${OP.menuId}]]_datagrid').bootstrapTable('refresh');
			 search = 0;
		}
	}
 }
 

//新增
middlegroup.admin.menu[[${OP.menuId}]].add = function(){
	middlegroup.showWindow({
			title:'增加主体',
			href:'/op_edit_[[${OP.menuId}]]',
			width:'50%',
			height:'50%',
			okhandler:function(){
				middlegroup.admin.menu[[${OP.menuId}]].save();
			},
			cancelhandler:function(){ 
				middlegroup.closeWindow();
			}
		}); 
	
}

	//编辑
middlegroup.admin.menu[[${OP.menuId}]].edit = function(){
	var rows = $('#admin_menu[[${OP.menuId}]]_datagrid').bootstrapTable('getSelections');
	if(rows.length == 0){
		middlegroup.toastrsAlert({
		     code:'info',
		     msg:'请选择你要编辑的记录'
		});
		return;
	}
	if(rows.length > 1){
		middlegroup.toastrsAlert({
		     code:'warning',
		     msg:'sorry , 只能选择一条进行编辑'
		});
		return;
	}
	middlegroup.showWindow({
		title:'编辑主体',
		href: '/op_edit_[[${OP.menuId}]]?id='+rows[0].id,
		width:'50%',
		height:'50%',
		okhandler:function(){
			middlegroup.admin.menu[[${OP.menuId}]].save();
		},
		cancelhandler:function(){
			middlegroup.closeWindow();
		}
	});
}

//配置主体端
middlegroup.admin.menu[[${OP.menuId}]].config = function(){
    var rows = $('#admin_menu[[${OP.menuId}]]_datagrid').bootstrapTable('getSelections');
    if(rows.length == 0){
        middlegroup.toastrsAlert({
            code:'info',
            msg:'请选择你要配置的主体'
        });
        return;
    }
    if(rows.length > 1){
        middlegroup.toastrsAlert({
            code:'warning',
            msg:'sorry , 只能选择一条进行配置'
        });
        return;
    }
    middlegroup.showWindow({
        title:'配置主体',
        href: '/op_config_[[${OP.menuId}]]?id='+rows[0].id,
        width:'50%',
        height:'50%'
    });
}
	
	//删除
middlegroup.admin.menu[[${OP.menuId}]].remove = function(){
	var rows =$('#admin_menu[[${OP.menuId}]]_datagrid').bootstrapTable('getSelections');
	if(rows.length==0){
		middlegroup.toastrsAlert({
		     code:'info',
		     msg:'请选择你要删除的记录'
		});
		return;
	}
	middlegroup.confirm(function(){
		var ps = [];
    	$.each(rows,function(i,n){
    		ps.push(n.id);
    	});
    	middlegroup.ajaxJson({url:'/op_remove_[[${OP.menuId}]]',data:{"ids":ps.join(",")}},function(){
    		$('#admin_menu[[${OP.menuId}]]_datagrid').bootstrapTable('refresh');
    	});
	});
}
	/*]]>*/
</script>

<div class="wrapper wrapper-content animated fadeInRight">
	<div class="ibox float-e-margins">
		<div class="ibox-content">
			<div class="panel panel-default">
				<div class="panel-body">
					<form id="formSearch" class="form-horizontal">
						<div class="form-group" style="margin-top: 15px">
							<label class="control-label col-sm-1">主体全称</label>
							<div class="col-sm-3">
								<input type="text" class="form-control" id="name" />
							</div>
							<label class="control-label col-sm-1">主体编号</label>
							<div class="col-sm-3">
								<input type="text" class="form-control" id="code" />
							</div>
							<div class="col-sm-4" style="text-align: left;">
								<button type="button"
									th:onclick="@{middlegroup.admin.menu{menuId}.search()(menuId=${OP.menuId})}"
									class="btn btn-primary">查询</button>
							</div>
						</div>
					</form>
				</div>
			</div>
			<div th:include="toolbar :: toolbar-operate"></div>
			<div class="table-responsive">
				<table th:id="@{admin_menu{menuId}_datagrid(menuId=${OP.menuId})}"
					data-toolbar="#toolbar" data-show-refresh="true"
					data-show-toggle="true" data-show-columns="true"
					data-show-footer="false" data-mobile-responsive="true">
				</table>
			</div>
		</div>
	</div>
</div>
</html>